<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let arr = [1, 34, 21, 1, , 22, 11, 4];

      let sort = arr.sort((a, b) => b - a);
      console.log(sort);

      // 购物车排序
      const cart = [
        {
          name: "iphone",
          price: 12000,
        },
        {
          name: "ipad",
          price: 8888,
        },
        {
          name: "mac",
          price: 15000,
        },
      ];

      let sortcart = cart.sort((a, b) => a.price - b.price);
      console.log(sortcart);
    </script>
  </body>
</html>
